<?php
namespace Home\Controller;
use Think\Controller;
/*
自动结算
 */
class AutobalanceController extends Controller {

	/**
	 * [自动结算流程]
	 * @Author   Axing
	 * @DateTime 2017-09-11
	 * @return   [type]     [description]
	 */
	public function auto() {
		$now_time = date('Y-m-d H:i:s');
		$orders = D('Goodsorders')->not_balance($arr);
		foreach($orders as $k => $v) {
			$time = date('Y-m-d H:i:s',strtotime("+7 day",strtotime($v['shou_huo_datetime'])));//确认收货后七天
			if($now_time >= $time) {
				$blance_state = D('Goodsorders')->update_blance_state($v['ordersid']);//更改结算状态
				$shop_money = D('shop')->update_money($v['shopid'], $v['blance_price']);//更新厂商钱包
				$shop_pay = array(
							'sid'        =>	$v['shopid'],
							'active_pay' =>	3,
							'amount'     =>	$v['blance_price'],
							'status'     =>	1,
							'style'      =>	4,
							'numbers'    =>	$v['numbers']
					);
				$shop_pay = D('ShopPay')->add_shop_pay($shop_pay);//新增一条转账记录
			}
		}
	}
}